package com.niit.dao;

import com.niit.pojo.StudentTable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;

/**
 * @author 杨铭
 * 2022/2/7,20:46
 */
public class deleteStudent {
    Configuration conf;

    public deleteStudent() {
        HbaseConnection hbaseConnection = new HbaseConnection();
        Configuration conf = hbaseConnection.connect();
        this.conf = conf;
    }
/*
* public static void main(String[] args) throws IOException {
        Configuration conf= HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","192.168.150.11");
        HBaseAdmin hBaseAdmin=new HBaseAdmin(conf);
        hBaseAdmin.deleteColumn("t1","cf3");
        System.out.println("delete CF ");
    }
*
*
* */

    public void delete(String tableName, StudentTable studentTable) {
        try {
            //判断表是否存在
            HBaseAdmin admin = new HBaseAdmin(conf);
            if (!admin.tableExists(Bytes.toBytes(tableName))) {
                System.out.println("该表格并不存在");
                System.exit(1);
            }
            HTable hTable = new HTable(conf, tableName);
            Delete delete = new Delete(Bytes.toBytes(studentTable.getStudentId()));
            hTable.delete(delete);
            hTable.close();
        } catch (Exception e) {

        }


    }
}
